package com.cs171.market.controller;
import com.cs171.market.entity.Student;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@CrossOrigin
@RestController
public class HelloController {

    @Value("${date}")
    private String date;


    @GetMapping("/hello")
    public String say(@RequestParam(value = "id",required = false,defaultValue = "0") Integer id){
        return "Hello World!"+id;
    }

    @GetMapping("/hel1")
    public String say1(){
        return date;
    }

    @GetMapping({"/hel2","hi"})
    public Object say2(){
        List<Student> l1 = new ArrayList<>();
        Student s1 = new Student("郑红","女",new BigDecimal(250));
        Student s2 = new Student("阮彤","女",new BigDecimal(250));
        l1.add(s1);
        l1.add(s2);

        return JSON.toJSON(l1);
    }

    @GetMapping("/hello/{id}")
    public String say3(@PathVariable("id") Integer id){
        return "Hello World!"+id;
    }

}
